package cn.kgc.jdbc;

import cn.kgc.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author mosin
 * date 2022/2/11
 * @version 1.0
 *
 */
public class JDBCDemo05 {

    public static void main(String[] args) {

        Connection connection = JDBCUtil.getConnection();
        PreparedStatement pstmt = null;
        String sql = "insert into usr(username,password,birth,create_time) values (?,?,?,?)";
        try {
             pstmt = connection.prepareStatement(sql);
             //设置参数
           pstmt.setString(1, "lisi");
           pstmt.setString(2, "123456");
           // Date date = new Date(new java.util.Date().getTime());
           // pstmt.setDate(3, date);
            //pstmt.setString(3, "1991-12-03");

            pstmt.setObject(3, "1991-12-03");
            pstmt.setString(4,"2022-02-01 12:12:12");
           int i = pstmt.executeUpdate();
            System.out.println("line = " + i);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.closeAll(null, pstmt, connection);
        }

    }
}
